﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Word_Mojo
{
    /// <summary>
    /// 
    /// </summary>
    class GamePlay
    {
        #region Private Data Members

        private List<Tuple<int, int, Tile>> tiles;
        private string word;
        private int pointValue;

        #endregion

        #region Construction

        /// <summary>
        /// requires List<Tuple<int, int, Tile>> representing the horizonal or vertical play
        /// </summary>
        /// <param name="coordinates"></param>
        public GamePlay(List<Tuple<int, int, Tile>> tiles)
        {
            this.tiles = tiles;
            this.pointValue = 0;
            this.word = "";

            if (this.PlayIsValid())
            {
                this.pointValue = this.CalculatePoints();
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// returns 0 when play is invalid
        /// </summary>
        /// <returns></returns>
        public int getPoints()
        {
            return this.pointValue;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public List<Tuple<int, int, Tile>> getTiles()
        {
            return this.tiles; 
        }

        #endregion

        #region Private Helper Methods

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool PlayIsValid()
        {
            foreach (Tuple<int, int, Tile> current in this.tiles)
            {
                this.word += current.Item3.Letter;
            }
            return EnglishDictionary.IsInDictionary(this.word);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private int CalculatePoints()
        {
            foreach (Tuple<int, int, Tile> current in this.tiles)
            {
                this.pointValue += current.Item3.PointValue;
            }
            return this.pointValue;
             
        }

        #endregion

    }
}
